{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 设置为inline风格\n",
    "%matplotlib inline\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "tuples = list(zip(*[['bar','bar','baz','baz',\n",
    "                     'foo','foo','qux','qux'],\n",
    "                   ['one','two','one','two',\n",
    "                    'one','two','one','two']]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex(levels=[['bar', 'baz', 'foo', 'qux'], ['one', 'two']],\n",
       "           labels=[[0, 0, 1, 1, 2, 2, 3, 3], [0, 1, 0, 1, 0, 1, 0, 1]],\n",
       "           names=['first', 'second'])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])\n",
    "index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>first</th>\n",
       "      <th>second</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">bar</th>\n",
       "      <th>one</th>\n",
       "      <td>1.392315</td>\n",
       "      <td>0.258399</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>-0.794224</td>\n",
       "      <td>0.157030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">baz</th>\n",
       "      <th>one</th>\n",
       "      <td>-1.674899</td>\n",
       "      <td>-0.680141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>1.564417</td>\n",
       "      <td>-0.058928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">foo</th>\n",
       "      <th>one</th>\n",
       "      <td>-0.490450</td>\n",
       "      <td>-0.480893</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>0.922584</td>\n",
       "      <td>1.122430</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">qux</th>\n",
       "      <th>one</th>\n",
       "      <td>-0.821056</td>\n",
       "      <td>-0.581660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>-0.576081</td>\n",
       "      <td>0.162416</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     A         B\n",
       "first second                    \n",
       "bar   one     1.392315  0.258399\n",
       "      two    -0.794224  0.157030\n",
       "baz   one    -1.674899 -0.680141\n",
       "      two     1.564417 -0.058928\n",
       "foo   one    -0.490450 -0.480893\n",
       "      two     0.922584  1.122430\n",
       "qux   one    -0.821056 -0.581660\n",
       "      two    -0.576081  0.162416"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(np.random.randn(8,2), index=index, columns=['A','B'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "first  second   \n",
       "bar    one     A    1.392315\n",
       "               B    0.258399\n",
       "       two     A   -0.794224\n",
       "               B    0.157030\n",
       "baz    one     A   -1.674899\n",
       "               B   -0.680141\n",
       "       two     A    1.564417\n",
       "               B   -0.058928\n",
       "foo    one     A   -0.490450\n",
       "               B   -0.480893\n",
       "       two     A    0.922584\n",
       "               B    1.122430\n",
       "qux    one     A   -0.821056\n",
       "               B   -0.581660\n",
       "       two     A   -0.576081\n",
       "               B    0.162416\n",
       "dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stacked = df.stack()\n",
    "stacked"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">A</th>\n",
       "      <th colspan=\"2\" halign=\"left\">B</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>second</th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>first</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>bar</th>\n",
       "      <td>1.392315</td>\n",
       "      <td>-0.794224</td>\n",
       "      <td>0.258399</td>\n",
       "      <td>0.157030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>baz</th>\n",
       "      <td>-1.674899</td>\n",
       "      <td>1.564417</td>\n",
       "      <td>-0.680141</td>\n",
       "      <td>-0.058928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>foo</th>\n",
       "      <td>-0.490450</td>\n",
       "      <td>0.922584</td>\n",
       "      <td>-0.480893</td>\n",
       "      <td>1.122430</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>qux</th>\n",
       "      <td>-0.821056</td>\n",
       "      <td>-0.576081</td>\n",
       "      <td>-0.581660</td>\n",
       "      <td>0.162416</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               A                   B          \n",
       "second       one       two       one       two\n",
       "first                                         \n",
       "bar     1.392315 -0.794224  0.258399  0.157030\n",
       "baz    -1.674899  1.564417 -0.680141 -0.058928\n",
       "foo    -0.490450  0.922584 -0.480893  1.122430\n",
       "qux    -0.821056 -0.576081 -0.581660  0.162416"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stacked = df.unstack()\n",
    "stacked"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   second  first\n",
       "A  one     bar      1.392315\n",
       "           baz     -1.674899\n",
       "           foo     -0.490450\n",
       "           qux     -0.821056\n",
       "   two     bar     -0.794224\n",
       "           baz      1.564417\n",
       "           foo      0.922584\n",
       "           qux     -0.576081\n",
       "B  one     bar      0.258399\n",
       "           baz     -0.680141\n",
       "           foo     -0.480893\n",
       "           qux     -0.581660\n",
       "   two     bar      0.157030\n",
       "           baz     -0.058928\n",
       "           foo      1.122430\n",
       "           qux      0.162416\n",
       "dtype: float64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stacked = df.unstack().unstack()\n",
    "stacked"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>second</th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>first</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>bar</th>\n",
       "      <td>1.392315</td>\n",
       "      <td>-0.794224</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>baz</th>\n",
       "      <td>-1.674899</td>\n",
       "      <td>1.564417</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>foo</th>\n",
       "      <td>-0.490450</td>\n",
       "      <td>0.922584</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>qux</th>\n",
       "      <td>-0.821056</td>\n",
       "      <td>-0.576081</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "second       one       two\n",
       "first                     \n",
       "bar     1.392315 -0.794224\n",
       "baz    -1.674899  1.564417\n",
       "foo    -0.490450  0.922584\n",
       "qux    -0.821056 -0.576081"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#数据透视表,值是A这一列，行索引为first，列索引为second\n",
    "df.pivot_table(values='A', index=['first'], columns=['second'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>first</th>\n",
       "      <th>second</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">bar</th>\n",
       "      <th>one</th>\n",
       "      <td>1.392315</td>\n",
       "      <td>0.258399</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>-0.794224</td>\n",
       "      <td>0.157030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">baz</th>\n",
       "      <th>one</th>\n",
       "      <td>-1.674899</td>\n",
       "      <td>-0.680141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>1.564417</td>\n",
       "      <td>-0.058928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">foo</th>\n",
       "      <th>one</th>\n",
       "      <td>-0.490450</td>\n",
       "      <td>-0.480893</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>0.922584</td>\n",
       "      <td>1.122430</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">qux</th>\n",
       "      <th>one</th>\n",
       "      <td>-0.821056</td>\n",
       "      <td>-0.581660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>-0.576081</td>\n",
       "      <td>0.162416</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     A         B\n",
       "first second                    \n",
       "bar   one     1.392315  0.258399\n",
       "      two    -0.794224  0.157030\n",
       "baz   one    -1.674899 -0.680141\n",
       "      two     1.564417 -0.058928\n",
       "foo   one    -0.490450 -0.480893\n",
       "      two     0.922584  1.122430\n",
       "qux   one    -0.821056 -0.581660\n",
       "      two    -0.576081  0.162416"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2018-06-01 00:00:00', '2018-06-01 00:00:01',\n",
       "               '2018-06-01 00:00:02', '2018-06-01 00:00:03',\n",
       "               '2018-06-01 00:00:04', '2018-06-01 00:00:05',\n",
       "               '2018-06-01 00:00:06', '2018-06-01 00:00:07',\n",
       "               '2018-06-01 00:00:08', '2018-06-01 00:00:09',\n",
       "               ...\n",
       "               '2018-06-01 00:09:50', '2018-06-01 00:09:51',\n",
       "               '2018-06-01 00:09:52', '2018-06-01 00:09:53',\n",
       "               '2018-06-01 00:09:54', '2018-06-01 00:09:55',\n",
       "               '2018-06-01 00:09:56', '2018-06-01 00:09:57',\n",
       "               '2018-06-01 00:09:58', '2018-06-01 00:09:59'],\n",
       "              dtype='datetime64[ns]', length=600, freq='S')"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#时间序列\n",
    "rng = pd.date_range('20180601', periods=600, freq='s')\n",
    "rng"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2018-06-01 00:00:00    279\n",
       "2018-06-01 00:00:01    314\n",
       "2018-06-01 00:00:02    132\n",
       "2018-06-01 00:00:03    154\n",
       "2018-06-01 00:00:04    472\n",
       "2018-06-01 00:00:05    476\n",
       "2018-06-01 00:00:06    380\n",
       "2018-06-01 00:00:07    194\n",
       "2018-06-01 00:00:08    263\n",
       "2018-06-01 00:00:09    343\n",
       "2018-06-01 00:00:10    160\n",
       "2018-06-01 00:00:11    201\n",
       "2018-06-01 00:00:12    263\n",
       "2018-06-01 00:00:13    246\n",
       "2018-06-01 00:00:14     18\n",
       "2018-06-01 00:00:15    159\n",
       "2018-06-01 00:00:16    144\n",
       "2018-06-01 00:00:17    145\n",
       "2018-06-01 00:00:18     36\n",
       "2018-06-01 00:00:19     93\n",
       "2018-06-01 00:00:20    298\n",
       "2018-06-01 00:00:21      9\n",
       "2018-06-01 00:00:22    311\n",
       "2018-06-01 00:00:23    362\n",
       "2018-06-01 00:00:24    340\n",
       "2018-06-01 00:00:25    113\n",
       "2018-06-01 00:00:26    360\n",
       "2018-06-01 00:00:27    329\n",
       "2018-06-01 00:00:28    468\n",
       "2018-06-01 00:00:29    229\n",
       "                      ... \n",
       "2018-06-01 00:09:30    183\n",
       "2018-06-01 00:09:31    429\n",
       "2018-06-01 00:09:32    299\n",
       "2018-06-01 00:09:33    424\n",
       "2018-06-01 00:09:34    196\n",
       "2018-06-01 00:09:35    226\n",
       "2018-06-01 00:09:36    293\n",
       "2018-06-01 00:09:37    222\n",
       "2018-06-01 00:09:38    470\n",
       "2018-06-01 00:09:39    393\n",
       "2018-06-01 00:09:40    211\n",
       "2018-06-01 00:09:41     72\n",
       "2018-06-01 00:09:42     13\n",
       "2018-06-01 00:09:43    376\n",
       "2018-06-01 00:09:44    321\n",
       "2018-06-01 00:09:45    218\n",
       "2018-06-01 00:09:46     18\n",
       "2018-06-01 00:09:47    439\n",
       "2018-06-01 00:09:48    473\n",
       "2018-06-01 00:09:49    293\n",
       "2018-06-01 00:09:50    417\n",
       "2018-06-01 00:09:51    338\n",
       "2018-06-01 00:09:52    341\n",
       "2018-06-01 00:09:53    158\n",
       "2018-06-01 00:09:54    215\n",
       "2018-06-01 00:09:55    154\n",
       "2018-06-01 00:09:56    260\n",
       "2018-06-01 00:09:57     79\n",
       "2018-06-01 00:09:58    362\n",
       "2018-06-01 00:09:59    271\n",
       "Freq: S, Length: 600, dtype: int32"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.Series(np.random.randint(0, 500, len(rng)), index=rng)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2018-06-01 00:00:00    243.150000\n",
       "2018-06-01 00:02:00    233.050000\n",
       "2018-06-01 00:04:00    240.308333\n",
       "2018-06-01 00:06:00    267.625000\n",
       "2018-06-01 00:08:00    246.000000\n",
       "Freq: 2T, dtype: float64"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.resample('2Min').mean()# 由原来的how='mean'修改了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PeriodIndex(['2000Q1', '2000Q2', '2000Q3', '2000Q4', '2001Q1', '2001Q2',\n",
       "             '2001Q3', '2001Q4', '2002Q1', '2002Q2', '2002Q3', '2002Q4',\n",
       "             '2003Q1', '2003Q2', '2003Q3', '2003Q4', '2004Q1', '2004Q2',\n",
       "             '2004Q3', '2004Q4', '2005Q1', '2005Q2', '2005Q3', '2005Q4',\n",
       "             '2006Q1', '2006Q2', '2006Q3', '2006Q4', '2007Q1', '2007Q2',\n",
       "             '2007Q3', '2007Q4', '2008Q1', '2008Q2', '2008Q3', '2008Q4',\n",
       "             '2009Q1', '2009Q2', '2009Q3', '2009Q4', '2010Q1', '2010Q2',\n",
       "             '2010Q3', '2010Q4', '2011Q1', '2011Q2', '2011Q3', '2011Q4',\n",
       "             '2012Q1', '2012Q2', '2012Q3', '2012Q4', '2013Q1', '2013Q2',\n",
       "             '2013Q3', '2013Q4', '2014Q1', '2014Q2', '2014Q3', '2014Q4',\n",
       "             '2015Q1', '2015Q2', '2015Q3', '2015Q4', '2016Q1'],\n",
       "            dtype='period[Q-DEC]', freq='Q-DEC')"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rng = pd.period_range('2000Q1', '2016Q1', freq='Q')\n",
    "rng"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2000-01-01', '2000-04-01', '2000-07-01', '2000-10-01',\n",
       "               '2001-01-01', '2001-04-01', '2001-07-01', '2001-10-01',\n",
       "               '2002-01-01', '2002-04-01', '2002-07-01', '2002-10-01',\n",
       "               '2003-01-01', '2003-04-01', '2003-07-01', '2003-10-01',\n",
       "               '2004-01-01', '2004-04-01', '2004-07-01', '2004-10-01',\n",
       "               '2005-01-01', '2005-04-01', '2005-07-01', '2005-10-01',\n",
       "               '2006-01-01', '2006-04-01', '2006-07-01', '2006-10-01',\n",
       "               '2007-01-01', '2007-04-01', '2007-07-01', '2007-10-01',\n",
       "               '2008-01-01', '2008-04-01', '2008-07-01', '2008-10-01',\n",
       "               '2009-01-01', '2009-04-01', '2009-07-01', '2009-10-01',\n",
       "               '2010-01-01', '2010-04-01', '2010-07-01', '2010-10-01',\n",
       "               '2011-01-01', '2011-04-01', '2011-07-01', '2011-10-01',\n",
       "               '2012-01-01', '2012-04-01', '2012-07-01', '2012-10-01',\n",
       "               '2013-01-01', '2013-04-01', '2013-07-01', '2013-10-01',\n",
       "               '2014-01-01', '2014-04-01', '2014-07-01', '2014-10-01',\n",
       "               '2015-01-01', '2015-04-01', '2015-07-01', '2015-10-01',\n",
       "               '2016-01-01'],\n",
       "              dtype='datetime64[ns]', freq='QS-OCT')"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rng.to_timestamp()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timedelta('28 days 00:00:00')"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Timestamp('20180301') - pd.Timestamp('20180201')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-2.343197</td>\n",
       "      <td>0.591256</td>\n",
       "      <td>0.653062</td>\n",
       "      <td>-1.041534</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.147419</td>\n",
       "      <td>1.446988</td>\n",
       "      <td>0.621339</td>\n",
       "      <td>2.448724</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.242194</td>\n",
       "      <td>1.134605</td>\n",
       "      <td>0.591352</td>\n",
       "      <td>-0.465338</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.017249</td>\n",
       "      <td>1.441591</td>\n",
       "      <td>1.196956</td>\n",
       "      <td>2.087314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.658759</td>\n",
       "      <td>2.028400</td>\n",
       "      <td>-0.539875</td>\n",
       "      <td>-0.804037</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-0.617433</td>\n",
       "      <td>0.778654</td>\n",
       "      <td>-1.258649</td>\n",
       "      <td>-0.543931</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.018344</td>\n",
       "      <td>-0.310136</td>\n",
       "      <td>0.355845</td>\n",
       "      <td>-0.649360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2.259695</td>\n",
       "      <td>0.205844</td>\n",
       "      <td>1.248547</td>\n",
       "      <td>-1.456638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>-0.458913</td>\n",
       "      <td>-0.470492</td>\n",
       "      <td>-1.650990</td>\n",
       "      <td>1.124029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.614551</td>\n",
       "      <td>-0.278962</td>\n",
       "      <td>-0.298046</td>\n",
       "      <td>-1.829402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.705409</td>\n",
       "      <td>-1.547774</td>\n",
       "      <td>0.348398</td>\n",
       "      <td>0.201868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>-0.777882</td>\n",
       "      <td>0.897451</td>\n",
       "      <td>-0.103769</td>\n",
       "      <td>-1.182174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.053166</td>\n",
       "      <td>0.090757</td>\n",
       "      <td>-0.613255</td>\n",
       "      <td>-2.558381</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0.002406</td>\n",
       "      <td>0.108677</td>\n",
       "      <td>1.147294</td>\n",
       "      <td>0.102909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.394712</td>\n",
       "      <td>0.835118</td>\n",
       "      <td>0.162575</td>\n",
       "      <td>0.439207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0.161011</td>\n",
       "      <td>0.901821</td>\n",
       "      <td>-0.517044</td>\n",
       "      <td>-1.069552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>-0.927661</td>\n",
       "      <td>0.682346</td>\n",
       "      <td>-0.720974</td>\n",
       "      <td>0.128333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>0.435542</td>\n",
       "      <td>-0.260472</td>\n",
       "      <td>-0.174919</td>\n",
       "      <td>1.530637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.022798</td>\n",
       "      <td>-0.578340</td>\n",
       "      <td>-0.963778</td>\n",
       "      <td>2.793827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0.738628</td>\n",
       "      <td>0.013779</td>\n",
       "      <td>2.145432</td>\n",
       "      <td>-0.718878</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>-0.291686</td>\n",
       "      <td>-0.553024</td>\n",
       "      <td>-0.492132</td>\n",
       "      <td>1.527851</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>-1.278782</td>\n",
       "      <td>0.024358</td>\n",
       "      <td>-0.140095</td>\n",
       "      <td>-0.149127</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>-1.391044</td>\n",
       "      <td>0.111683</td>\n",
       "      <td>0.674228</td>\n",
       "      <td>-1.479790</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>0.362333</td>\n",
       "      <td>0.082441</td>\n",
       "      <td>0.247529</td>\n",
       "      <td>0.549812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>-1.191333</td>\n",
       "      <td>-0.338307</td>\n",
       "      <td>0.494903</td>\n",
       "      <td>1.152627</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.214946</td>\n",
       "      <td>1.231893</td>\n",
       "      <td>-2.880095</td>\n",
       "      <td>-0.504492</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>-0.199706</td>\n",
       "      <td>0.047797</td>\n",
       "      <td>-1.276589</td>\n",
       "      <td>-0.127992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>-1.093969</td>\n",
       "      <td>0.199155</td>\n",
       "      <td>-0.232444</td>\n",
       "      <td>0.639500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>0.089714</td>\n",
       "      <td>2.085731</td>\n",
       "      <td>-0.133650</td>\n",
       "      <td>-0.277191</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>-0.048589</td>\n",
       "      <td>1.536452</td>\n",
       "      <td>-0.251871</td>\n",
       "      <td>0.229140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>-0.152586</td>\n",
       "      <td>-2.030659</td>\n",
       "      <td>-1.157389</td>\n",
       "      <td>1.081083</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>0.963333</td>\n",
       "      <td>-0.421543</td>\n",
       "      <td>0.463552</td>\n",
       "      <td>0.160575</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>-0.251205</td>\n",
       "      <td>0.653229</td>\n",
       "      <td>0.080610</td>\n",
       "      <td>-0.268781</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>1.028786</td>\n",
       "      <td>2.042928</td>\n",
       "      <td>-0.127565</td>\n",
       "      <td>-0.227832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>-0.590305</td>\n",
       "      <td>-0.320405</td>\n",
       "      <td>-1.074100</td>\n",
       "      <td>0.070875</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>-0.870313</td>\n",
       "      <td>-0.276450</td>\n",
       "      <td>-0.143057</td>\n",
       "      <td>0.153675</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>0.828052</td>\n",
       "      <td>1.030301</td>\n",
       "      <td>0.312630</td>\n",
       "      <td>0.036469</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>-0.386832</td>\n",
       "      <td>-0.805867</td>\n",
       "      <td>0.061903</td>\n",
       "      <td>-0.639622</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>0.560403</td>\n",
       "      <td>1.842608</td>\n",
       "      <td>0.452572</td>\n",
       "      <td>-0.340720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>-0.456387</td>\n",
       "      <td>-1.492591</td>\n",
       "      <td>1.356751</td>\n",
       "      <td>-2.020540</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>-0.716996</td>\n",
       "      <td>0.437136</td>\n",
       "      <td>0.405746</td>\n",
       "      <td>-1.548933</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>-0.472881</td>\n",
       "      <td>0.054897</td>\n",
       "      <td>0.105567</td>\n",
       "      <td>0.025533</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>1.056517</td>\n",
       "      <td>-0.468066</td>\n",
       "      <td>0.711097</td>\n",
       "      <td>-0.822320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>-1.480937</td>\n",
       "      <td>-2.001297</td>\n",
       "      <td>0.420291</td>\n",
       "      <td>1.787173</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>-1.011252</td>\n",
       "      <td>1.088157</td>\n",
       "      <td>-0.856510</td>\n",
       "      <td>0.639469</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>-0.463156</td>\n",
       "      <td>3.129097</td>\n",
       "      <td>-0.470238</td>\n",
       "      <td>0.929912</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>-0.537892</td>\n",
       "      <td>0.153107</td>\n",
       "      <td>-0.151179</td>\n",
       "      <td>1.986263</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>0.342979</td>\n",
       "      <td>-0.792489</td>\n",
       "      <td>1.189193</td>\n",
       "      <td>1.515633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>1.831871</td>\n",
       "      <td>0.086116</td>\n",
       "      <td>-2.206238</td>\n",
       "      <td>1.397732</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>-0.032017</td>\n",
       "      <td>-1.044514</td>\n",
       "      <td>-0.840393</td>\n",
       "      <td>1.674153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>-0.538999</td>\n",
       "      <td>-1.173623</td>\n",
       "      <td>-1.073890</td>\n",
       "      <td>1.969308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>-0.669302</td>\n",
       "      <td>-0.274812</td>\n",
       "      <td>0.561113</td>\n",
       "      <td>0.483538</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>-1.267700</td>\n",
       "      <td>1.531968</td>\n",
       "      <td>1.650218</td>\n",
       "      <td>0.295969</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>-0.067458</td>\n",
       "      <td>-0.579526</td>\n",
       "      <td>-1.151589</td>\n",
       "      <td>-1.147360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>0.023480</td>\n",
       "      <td>1.897715</td>\n",
       "      <td>-0.413801</td>\n",
       "      <td>-0.978077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>0.844990</td>\n",
       "      <td>0.542070</td>\n",
       "      <td>0.445593</td>\n",
       "      <td>-0.713182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>0.584429</td>\n",
       "      <td>0.086347</td>\n",
       "      <td>-0.606451</td>\n",
       "      <td>-0.271413</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>-0.710546</td>\n",
       "      <td>0.069594</td>\n",
       "      <td>-0.666589</td>\n",
       "      <td>1.217053</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>0.435394</td>\n",
       "      <td>-0.262983</td>\n",
       "      <td>-0.151974</td>\n",
       "      <td>-1.752065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>-1.022321</td>\n",
       "      <td>-0.978850</td>\n",
       "      <td>-0.120849</td>\n",
       "      <td>-1.634415</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           A         B         C         D\n",
       "0  -2.343197  0.591256  0.653062 -1.041534\n",
       "1   0.147419  1.446988  0.621339  2.448724\n",
       "2  -0.242194  1.134605  0.591352 -0.465338\n",
       "3   0.017249  1.441591  1.196956  2.087314\n",
       "4   0.658759  2.028400 -0.539875 -0.804037\n",
       "5  -0.617433  0.778654 -1.258649 -0.543931\n",
       "6   1.018344 -0.310136  0.355845 -0.649360\n",
       "7   2.259695  0.205844  1.248547 -1.456638\n",
       "8  -0.458913 -0.470492 -1.650990  1.124029\n",
       "9  -0.614551 -0.278962 -0.298046 -1.829402\n",
       "10  0.705409 -1.547774  0.348398  0.201868\n",
       "11 -0.777882  0.897451 -0.103769 -1.182174\n",
       "12  0.053166  0.090757 -0.613255 -2.558381\n",
       "13  0.002406  0.108677  1.147294  0.102909\n",
       "14  0.394712  0.835118  0.162575  0.439207\n",
       "15  0.161011  0.901821 -0.517044 -1.069552\n",
       "16 -0.927661  0.682346 -0.720974  0.128333\n",
       "17  0.435542 -0.260472 -0.174919  1.530637\n",
       "18  0.022798 -0.578340 -0.963778  2.793827\n",
       "19  0.738628  0.013779  2.145432 -0.718878\n",
       "20 -0.291686 -0.553024 -0.492132  1.527851\n",
       "21 -1.278782  0.024358 -0.140095 -0.149127\n",
       "22 -1.391044  0.111683  0.674228 -1.479790\n",
       "23  0.362333  0.082441  0.247529  0.549812\n",
       "24 -1.191333 -0.338307  0.494903  1.152627\n",
       "25  0.214946  1.231893 -2.880095 -0.504492\n",
       "26 -0.199706  0.047797 -1.276589 -0.127992\n",
       "27 -1.093969  0.199155 -0.232444  0.639500\n",
       "28  0.089714  2.085731 -0.133650 -0.277191\n",
       "29 -0.048589  1.536452 -0.251871  0.229140\n",
       "..       ...       ...       ...       ...\n",
       "70 -0.152586 -2.030659 -1.157389  1.081083\n",
       "71  0.963333 -0.421543  0.463552  0.160575\n",
       "72 -0.251205  0.653229  0.080610 -0.268781\n",
       "73  1.028786  2.042928 -0.127565 -0.227832\n",
       "74 -0.590305 -0.320405 -1.074100  0.070875\n",
       "75 -0.870313 -0.276450 -0.143057  0.153675\n",
       "76  0.828052  1.030301  0.312630  0.036469\n",
       "77 -0.386832 -0.805867  0.061903 -0.639622\n",
       "78  0.560403  1.842608  0.452572 -0.340720\n",
       "79 -0.456387 -1.492591  1.356751 -2.020540\n",
       "80 -0.716996  0.437136  0.405746 -1.548933\n",
       "81 -0.472881  0.054897  0.105567  0.025533\n",
       "82  1.056517 -0.468066  0.711097 -0.822320\n",
       "83 -1.480937 -2.001297  0.420291  1.787173\n",
       "84 -1.011252  1.088157 -0.856510  0.639469\n",
       "85 -0.463156  3.129097 -0.470238  0.929912\n",
       "86 -0.537892  0.153107 -0.151179  1.986263\n",
       "87  0.342979 -0.792489  1.189193  1.515633\n",
       "88  1.831871  0.086116 -2.206238  1.397732\n",
       "89 -0.032017 -1.044514 -0.840393  1.674153\n",
       "90 -0.538999 -1.173623 -1.073890  1.969308\n",
       "91 -0.669302 -0.274812  0.561113  0.483538\n",
       "92 -1.267700  1.531968  1.650218  0.295969\n",
       "93 -0.067458 -0.579526 -1.151589 -1.147360\n",
       "94  0.023480  1.897715 -0.413801 -0.978077\n",
       "95  0.844990  0.542070  0.445593 -0.713182\n",
       "96  0.584429  0.086347 -0.606451 -0.271413\n",
       "97 -0.710546  0.069594 -0.666589  1.217053\n",
       "98  0.435394 -0.262983 -0.151974 -1.752065\n",
       "99 -1.022321 -0.978850 -0.120849 -1.634415\n",
       "\n",
       "[100 rows x 4 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(np.random.randn(100,4), columns=list('ABCD'))\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 驱动器 C 中的卷没有标签。\n",
      " 卷的序列号是 D83C-D5BD\n",
      "\n",
      " C:\\Users\\Administrator 的目录\n",
      "\n",
      "2018/06/22  20:15    <DIR>          .\n",
      "2018/06/22  20:15    <DIR>          ..\n",
      "2014/03/04  22:11    <DIR>          .android\n",
      "2017/10/25  12:58    <DIR>          .astropy\n",
      "2018/04/25  15:27               610 .bash_history\n",
      "2017/07/10  00:23                74 .gitconfig\n",
      "2017/09/27  21:39    <DIR>          .idlerc\n",
      "2018/06/22  19:25    <DIR>          .ipynb_checkpoints\n",
      "2017/10/23  15:00    <DIR>          .ipython\n",
      "2018/06/15  15:16    <DIR>          .jupyter\n",
      "2018/06/22  19:27    <DIR>          .matplotlib\n",
      "2016/02/01  21:49    <DIR>          .oracle_jre_usage\n",
      "2017/08/15  16:42    <DIR>          .PyCharm2017.2\n",
      "2018/05/25  20:29                 0 .pythonhist\n",
      "2017/10/23  15:29    <DIR>          .spyder-py3\n",
      "2017/07/10  00:12    <DIR>          .ssh\n",
      "2018/06/08  16:55    <DIR>          AppData\n",
      "2017/06/14  14:16    <DIR>          Contacts\n",
      "2018/06/22  20:15             8,251 data.csv\n",
      "2018/06/22  16:45    <DIR>          Desktop\n",
      "2017/08/14  20:00    <DIR>          Documents\n",
      "2018/06/21  20:44    <DIR>          Downloads\n",
      "2016/09/10  16:14    <DIR>          fancy\n",
      "2018/04/28  14:08    <DIR>          Favorites\n",
      "2018/05/28  18:23            11,159 gsview32.ini\n",
      "2017/07/22  16:29    <DIR>          HBuilder\n",
      "2017/07/22  16:32    <DIR>          HBuilder settings\n",
      "2018/04/25  13:31    <DIR>          learngit\n",
      "2017/06/14  14:16    <DIR>          Links\n",
      "2017/08/14  19:56                74 mercurial.ini\n",
      "2017/12/13  22:35                34 mm.cfg\n",
      "2018/06/20  14:55    <DIR>          Music\n",
      "2018/06/21  16:03            48,131 pandas_demo1.ipynb\n",
      "2018/06/22  20:14            23,114 pandas_demo2.ipynb\n",
      "2018/05/19  18:55    <DIR>          Pictures\n",
      "2017/10/11  21:07    <DIR>          PycharmProjects\n",
      "2018/05/14  16:42               816 pyhton_demo.ipynb\n",
      "2017/06/14  14:16    <DIR>          Saved Games\n",
      "2017/08/11  13:45    <DIR>          Searches\n",
      "2017/08/15  16:05    <DIR>          sunblog\n",
      "2017/10/19  17:57    <DIR>          Tracing\n",
      "2017/11/29  16:27                72 Untitled.ipynb\n",
      "2017/11/29  16:27                 0 untitled.txt\n",
      "2018/06/15  15:29               581 Untitled1.ipynb\n",
      "2017/07/22  21:15    <DIR>          Videos\n",
      "2017/07/14  18:41    <DIR>          WebstormProjects\n",
      "              13 个文件         92,916 字节\n",
      "              33 个目录 34,009,100,288 可用字节\n"
     ]
    }
   ],
   "source": [
    "df.to_csv('data.csv')\n",
    "%ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%more data.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-2.343197</td>\n",
       "      <td>0.591256</td>\n",
       "      <td>0.653062</td>\n",
       "      <td>-1.041534</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.147419</td>\n",
       "      <td>1.446988</td>\n",
       "      <td>0.621339</td>\n",
       "      <td>2.448724</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.242194</td>\n",
       "      <td>1.134605</td>\n",
       "      <td>0.591352</td>\n",
       "      <td>-0.465338</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.017249</td>\n",
       "      <td>1.441591</td>\n",
       "      <td>1.196956</td>\n",
       "      <td>2.087314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.658759</td>\n",
       "      <td>2.028400</td>\n",
       "      <td>-0.539875</td>\n",
       "      <td>-0.804037</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-0.617433</td>\n",
       "      <td>0.778654</td>\n",
       "      <td>-1.258649</td>\n",
       "      <td>-0.543931</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.018344</td>\n",
       "      <td>-0.310136</td>\n",
       "      <td>0.355845</td>\n",
       "      <td>-0.649360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2.259695</td>\n",
       "      <td>0.205844</td>\n",
       "      <td>1.248547</td>\n",
       "      <td>-1.456638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>-0.458913</td>\n",
       "      <td>-0.470492</td>\n",
       "      <td>-1.650990</td>\n",
       "      <td>1.124029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.614551</td>\n",
       "      <td>-0.278962</td>\n",
       "      <td>-0.298046</td>\n",
       "      <td>-1.829402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.705409</td>\n",
       "      <td>-1.547774</td>\n",
       "      <td>0.348398</td>\n",
       "      <td>0.201868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>-0.777882</td>\n",
       "      <td>0.897451</td>\n",
       "      <td>-0.103769</td>\n",
       "      <td>-1.182174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.053166</td>\n",
       "      <td>0.090757</td>\n",
       "      <td>-0.613255</td>\n",
       "      <td>-2.558381</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0.002406</td>\n",
       "      <td>0.108677</td>\n",
       "      <td>1.147294</td>\n",
       "      <td>0.102909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.394712</td>\n",
       "      <td>0.835118</td>\n",
       "      <td>0.162575</td>\n",
       "      <td>0.439207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0.161011</td>\n",
       "      <td>0.901821</td>\n",
       "      <td>-0.517044</td>\n",
       "      <td>-1.069552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>-0.927661</td>\n",
       "      <td>0.682346</td>\n",
       "      <td>-0.720974</td>\n",
       "      <td>0.128333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>0.435542</td>\n",
       "      <td>-0.260472</td>\n",
       "      <td>-0.174919</td>\n",
       "      <td>1.530637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.022798</td>\n",
       "      <td>-0.578340</td>\n",
       "      <td>-0.963778</td>\n",
       "      <td>2.793827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0.738628</td>\n",
       "      <td>0.013779</td>\n",
       "      <td>2.145432</td>\n",
       "      <td>-0.718878</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>-0.291686</td>\n",
       "      <td>-0.553024</td>\n",
       "      <td>-0.492132</td>\n",
       "      <td>1.527851</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>-1.278782</td>\n",
       "      <td>0.024358</td>\n",
       "      <td>-0.140095</td>\n",
       "      <td>-0.149127</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>-1.391044</td>\n",
       "      <td>0.111683</td>\n",
       "      <td>0.674228</td>\n",
       "      <td>-1.479790</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>0.362333</td>\n",
       "      <td>0.082441</td>\n",
       "      <td>0.247529</td>\n",
       "      <td>0.549812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>-1.191333</td>\n",
       "      <td>-0.338307</td>\n",
       "      <td>0.494903</td>\n",
       "      <td>1.152627</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.214946</td>\n",
       "      <td>1.231893</td>\n",
       "      <td>-2.880095</td>\n",
       "      <td>-0.504492</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>-0.199706</td>\n",
       "      <td>0.047797</td>\n",
       "      <td>-1.276589</td>\n",
       "      <td>-0.127992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>-1.093969</td>\n",
       "      <td>0.199155</td>\n",
       "      <td>-0.232444</td>\n",
       "      <td>0.639500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>0.089714</td>\n",
       "      <td>2.085731</td>\n",
       "      <td>-0.133650</td>\n",
       "      <td>-0.277191</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>-0.048589</td>\n",
       "      <td>1.536452</td>\n",
       "      <td>-0.251871</td>\n",
       "      <td>0.229140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>-0.152586</td>\n",
       "      <td>-2.030659</td>\n",
       "      <td>-1.157389</td>\n",
       "      <td>1.081083</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>0.963333</td>\n",
       "      <td>-0.421543</td>\n",
       "      <td>0.463552</td>\n",
       "      <td>0.160575</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>-0.251205</td>\n",
       "      <td>0.653229</td>\n",
       "      <td>0.080610</td>\n",
       "      <td>-0.268781</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>1.028786</td>\n",
       "      <td>2.042928</td>\n",
       "      <td>-0.127565</td>\n",
       "      <td>-0.227832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>-0.590305</td>\n",
       "      <td>-0.320405</td>\n",
       "      <td>-1.074100</td>\n",
       "      <td>0.070875</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>-0.870313</td>\n",
       "      <td>-0.276450</td>\n",
       "      <td>-0.143057</td>\n",
       "      <td>0.153675</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>0.828052</td>\n",
       "      <td>1.030301</td>\n",
       "      <td>0.312630</td>\n",
       "      <td>0.036469</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>-0.386832</td>\n",
       "      <td>-0.805867</td>\n",
       "      <td>0.061903</td>\n",
       "      <td>-0.639622</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>0.560403</td>\n",
       "      <td>1.842608</td>\n",
       "      <td>0.452572</td>\n",
       "      <td>-0.340720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>-0.456387</td>\n",
       "      <td>-1.492591</td>\n",
       "      <td>1.356751</td>\n",
       "      <td>-2.020540</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>-0.716996</td>\n",
       "      <td>0.437136</td>\n",
       "      <td>0.405746</td>\n",
       "      <td>-1.548933</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>-0.472881</td>\n",
       "      <td>0.054897</td>\n",
       "      <td>0.105567</td>\n",
       "      <td>0.025533</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>1.056517</td>\n",
       "      <td>-0.468066</td>\n",
       "      <td>0.711097</td>\n",
       "      <td>-0.822320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>-1.480937</td>\n",
       "      <td>-2.001297</td>\n",
       "      <td>0.420291</td>\n",
       "      <td>1.787173</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>-1.011252</td>\n",
       "      <td>1.088157</td>\n",
       "      <td>-0.856510</td>\n",
       "      <td>0.639469</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>-0.463156</td>\n",
       "      <td>3.129097</td>\n",
       "      <td>-0.470238</td>\n",
       "      <td>0.929912</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>-0.537892</td>\n",
       "      <td>0.153107</td>\n",
       "      <td>-0.151179</td>\n",
       "      <td>1.986263</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>0.342979</td>\n",
       "      <td>-0.792489</td>\n",
       "      <td>1.189193</td>\n",
       "      <td>1.515633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>1.831871</td>\n",
       "      <td>0.086116</td>\n",
       "      <td>-2.206238</td>\n",
       "      <td>1.397732</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>-0.032017</td>\n",
       "      <td>-1.044514</td>\n",
       "      <td>-0.840393</td>\n",
       "      <td>1.674153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>-0.538999</td>\n",
       "      <td>-1.173623</td>\n",
       "      <td>-1.073890</td>\n",
       "      <td>1.969308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>-0.669302</td>\n",
       "      <td>-0.274812</td>\n",
       "      <td>0.561113</td>\n",
       "      <td>0.483538</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>-1.267700</td>\n",
       "      <td>1.531968</td>\n",
       "      <td>1.650218</td>\n",
       "      <td>0.295969</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>-0.067458</td>\n",
       "      <td>-0.579526</td>\n",
       "      <td>-1.151589</td>\n",
       "      <td>-1.147360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>0.023480</td>\n",
       "      <td>1.897715</td>\n",
       "      <td>-0.413801</td>\n",
       "      <td>-0.978077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>0.844990</td>\n",
       "      <td>0.542070</td>\n",
       "      <td>0.445593</td>\n",
       "      <td>-0.713182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>0.584429</td>\n",
       "      <td>0.086347</td>\n",
       "      <td>-0.606451</td>\n",
       "      <td>-0.271413</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>-0.710546</td>\n",
       "      <td>0.069594</td>\n",
       "      <td>-0.666589</td>\n",
       "      <td>1.217053</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>0.435394</td>\n",
       "      <td>-0.262983</td>\n",
       "      <td>-0.151974</td>\n",
       "      <td>-1.752065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>-1.022321</td>\n",
       "      <td>-0.978850</td>\n",
       "      <td>-0.120849</td>\n",
       "      <td>-1.634415</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           A         B         C         D\n",
       "0  -2.343197  0.591256  0.653062 -1.041534\n",
       "1   0.147419  1.446988  0.621339  2.448724\n",
       "2  -0.242194  1.134605  0.591352 -0.465338\n",
       "3   0.017249  1.441591  1.196956  2.087314\n",
       "4   0.658759  2.028400 -0.539875 -0.804037\n",
       "5  -0.617433  0.778654 -1.258649 -0.543931\n",
       "6   1.018344 -0.310136  0.355845 -0.649360\n",
       "7   2.259695  0.205844  1.248547 -1.456638\n",
       "8  -0.458913 -0.470492 -1.650990  1.124029\n",
       "9  -0.614551 -0.278962 -0.298046 -1.829402\n",
       "10  0.705409 -1.547774  0.348398  0.201868\n",
       "11 -0.777882  0.897451 -0.103769 -1.182174\n",
       "12  0.053166  0.090757 -0.613255 -2.558381\n",
       "13  0.002406  0.108677  1.147294  0.102909\n",
       "14  0.394712  0.835118  0.162575  0.439207\n",
       "15  0.161011  0.901821 -0.517044 -1.069552\n",
       "16 -0.927661  0.682346 -0.720974  0.128333\n",
       "17  0.435542 -0.260472 -0.174919  1.530637\n",
       "18  0.022798 -0.578340 -0.963778  2.793827\n",
       "19  0.738628  0.013779  2.145432 -0.718878\n",
       "20 -0.291686 -0.553024 -0.492132  1.527851\n",
       "21 -1.278782  0.024358 -0.140095 -0.149127\n",
       "22 -1.391044  0.111683  0.674228 -1.479790\n",
       "23  0.362333  0.082441  0.247529  0.549812\n",
       "24 -1.191333 -0.338307  0.494903  1.152627\n",
       "25  0.214946  1.231893 -2.880095 -0.504492\n",
       "26 -0.199706  0.047797 -1.276589 -0.127992\n",
       "27 -1.093969  0.199155 -0.232444  0.639500\n",
       "28  0.089714  2.085731 -0.133650 -0.277191\n",
       "29 -0.048589  1.536452 -0.251871  0.229140\n",
       "..       ...       ...       ...       ...\n",
       "70 -0.152586 -2.030659 -1.157389  1.081083\n",
       "71  0.963333 -0.421543  0.463552  0.160575\n",
       "72 -0.251205  0.653229  0.080610 -0.268781\n",
       "73  1.028786  2.042928 -0.127565 -0.227832\n",
       "74 -0.590305 -0.320405 -1.074100  0.070875\n",
       "75 -0.870313 -0.276450 -0.143057  0.153675\n",
       "76  0.828052  1.030301  0.312630  0.036469\n",
       "77 -0.386832 -0.805867  0.061903 -0.639622\n",
       "78  0.560403  1.842608  0.452572 -0.340720\n",
       "79 -0.456387 -1.492591  1.356751 -2.020540\n",
       "80 -0.716996  0.437136  0.405746 -1.548933\n",
       "81 -0.472881  0.054897  0.105567  0.025533\n",
       "82  1.056517 -0.468066  0.711097 -0.822320\n",
       "83 -1.480937 -2.001297  0.420291  1.787173\n",
       "84 -1.011252  1.088157 -0.856510  0.639469\n",
       "85 -0.463156  3.129097 -0.470238  0.929912\n",
       "86 -0.537892  0.153107 -0.151179  1.986263\n",
       "87  0.342979 -0.792489  1.189193  1.515633\n",
       "88  1.831871  0.086116 -2.206238  1.397732\n",
       "89 -0.032017 -1.044514 -0.840393  1.674153\n",
       "90 -0.538999 -1.173623 -1.073890  1.969308\n",
       "91 -0.669302 -0.274812  0.561113  0.483538\n",
       "92 -1.267700  1.531968  1.650218  0.295969\n",
       "93 -0.067458 -0.579526 -1.151589 -1.147360\n",
       "94  0.023480  1.897715 -0.413801 -0.978077\n",
       "95  0.844990  0.542070  0.445593 -0.713182\n",
       "96  0.584429  0.086347 -0.606451 -0.271413\n",
       "97 -0.710546  0.069594 -0.666589  1.217053\n",
       "98  0.435394 -0.262983 -0.151974 -1.752065\n",
       "99 -1.022321 -0.978850 -0.120849 -1.634415\n",
       "\n",
       "[100 rows x 4 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv('data.csv', index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
